package com.clkj.sunhelp.adapter.vp;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;

import com.clkj.sunhelp.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2017/3/30.
 */

public class VpAdapterForBanner  extends PagerAdapter {

    List<View> viewLists;
    List<Integer> localResIdList;
    Context mContext;


    public VpAdapterForBanner(Context context,List<View> lists, List<Integer> localResIdList) {
        mContext = context;
        viewLists = lists;
        this.localResIdList = localResIdList;

    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return viewLists.size();
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        // TODO Auto-generated method stub
        return arg0 == arg1;
    }

    @Override
    public void destroyItem(View view, int position, Object object) {
        ((ViewPager) view).removeView(viewLists.get(position));
    }

    @Override
    public Object instantiateItem(View view, int position) {

        View showView = viewLists.get(position);
        ImageView bannerIv = (ImageView) showView.findViewById(R.id.iv_banner);

        Picasso.with(mContext)
                .load(localResIdList.get(position))
                .placeholder(R.drawable.pic_default_trans)
                .error(R.drawable.pic_default_trans)
                .into(bannerIv);

        ((ViewPager) view).addView(viewLists.get(position), 0);

        return viewLists.get(position);
    }



}


